package com.zcsy.manage.service.system.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zcsy.manage.model.system.Org;
import com.zcsy.manage.persistence.system.OrgDao;
import com.zcsy.manage.service.system.IOrgService;

/**
 * @Title: OrgServiceImpl.java
 * @Package： com.zcsy.shop.service.impl 
 * @Description: 组织服务层接口类
 *
 * @author tanghan barbadosliy@163.com
 * @Copyright: 2015 武汉中财数元信息技术有限公司 All rights reserved.
 * @date 2015年7月7日
 * @version 1.0
 * @see JDK1.7.0_75
 * @since
 */
@Service
public class OrgServiceImpl extends SystemComService implements IOrgService{

	@Autowired
	private OrgDao orgDao;
	
	@Override
	public Org selectByPrimaryKey(String id) {
		return orgDao.selectByPrimaryKey(id);
	}

	@Override
	public int deleteByPrimaryKey(String id) {
		return orgDao.deleteByPrimaryKey(id);
	}

	@Override
	public int insert(Org record) {
		return orgDao.insert(record);
	}

	@Override
	public int updateByPrimaryKey(String orgId,String orgName) {
		Org org = orgDao.selectByPrimaryKey(orgId);
		org.setOrgName(orgName);
		return orgDao.updateByPrimaryKey(org);
	}

	@Override
	public List<Org> getAll() {
		return orgDao.getAll();
	}

	@Override
	public String getFullOrgName(String orgName,Org depart, Map<String, Org> orgMap) {
		String parentId = depart.getOrgPid();
		if(parentId!=null){
			Org parentOrg = orgMap.get(parentId);
			if(parentOrg!=null){
				orgName = parentOrg.getOrgName()+ " / " + orgName;
				return getFullOrgName(orgName,parentOrg,orgMap);
			}
		}
		return orgName;
	}

	/**
	 * {@inheritDoc}
	 * @see com.zcsy.shop.service.system.framework.service.IOrgService#getOrgByPId(java.lang.Integer)
	 */
	@Override
	public List<Org> getOrgByPId(String orgPid) {
		return orgDao.getOrgByPId(orgPid);
	}

	@Override
	public List<Org> queryOrgByType(Integer orgType) {
		return orgDao.queryOrgByType(orgType);
	}

	@Override
	public int updateOrg(Org org) {
		return orgDao.updateOrg(org);
	}

}
